package com.gk.panda.apis.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gk.panda.apis.dto.OperationLogDto;
import com.gk.panda.apis.log.Log;
import com.gk.panda.apis.service.LogService;
import com.gk.panda.commons.result.Result;
import com.gk.panda.pojo.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * 操作日志控制器
 */
@RestController
@RequestMapping("/log")
@Api(tags = "操作日志")
public class OperationLogController {

    @Autowired
    private LogService logService;

    @ApiOperation(value = "获取日志列表")
    @PostMapping
    public Result<Page<OperationLog>> listOperationLog(@RequestBody OperationLogDto dto) {
        Page<OperationLog> operationLogPage = logService.listOperationLog(dto);
        return Result.ok(operationLogPage);
    }

    @ApiOperation(value = "导出日志")
    @Log
    @GetMapping("/export")
    public void export(HttpServletResponse response) {
        logService.export(response);
    }
}
